//
//  RegularBusViewModel.m
//  didacar
//
//  Created by 度周末网络-王腾 on 16/1/11.
//  Copyright © 2016年 dzmmac. All rights reserved.
//

#import "RegularBusViewModel.h"

@implementation RegularBusViewModel

-(void)getThroughBusRecommend:(DealDataResultBlock)result{
    
    
    NSMutableDictionary *postDic = [[NSMutableDictionary alloc ] init];
    [postDic setObj:@(self.cityId).stringValue   forKey:@"CityId"];
   
    
    WEAKSELF
    [[BaseHttpRequest sharedInstance] sendRequestToPost:ThroughRecommendLine withData:postDic alertMessage:nil success:^(NSDictionary *dicData) {
        
        [weakSelf.resultList removeAllObjects];
        
        for (NSDictionary *dic in [dicData objectForKey:@"RecommendStraightTrainlist"]) {
            RegularBusLineModel *model = [[RegularBusLineModel alloc ] initWithDictionary:dic];
            [weakSelf.resultList addObject:model];
        }
        
        if (weakSelf.resultList.count == weakSelf.pageCount) {
            weakSelf.isLoadMore = YES;
        }else{
            weakSelf.isLoadMore = NO;
        }
        
        result(1,nil,nil);
    } error:^(NSString *errorMsg) {
        result(0,nil,errorMsg);
    }];
}

-(void)getRegularBusRecommend:(DealDataResultBlock)result{
    
    NSMutableDictionary *postDic = [[NSMutableDictionary alloc ] init];
    [postDic setObj:@(self.cityId).stringValue   forKey:@"CityId"];
    [postDic setObj:@(self.startLng).stringValue forKey:@"StartLng"];
    [postDic setObj:@(self.startLat).stringValue forKey:@"StartLat"];
    [postDic setObj:@(self.endLng).stringValue   forKey:@"EndLng"];
    [postDic setObj:@(self.endLat).stringValue   forKey:@"EndLat"];
    
    WEAKSELF
    [[BaseHttpRequest sharedInstance] sendRequestToPost:RegularRecommendLine withData:postDic alertMessage:nil success:^(NSDictionary *dicData) {
        
        [weakSelf.resultList removeAllObjects];
        
        for (NSDictionary *dic in [dicData objectForKey:@"LineList"]) {
            RegularBusLineModel *model = [[RegularBusLineModel alloc ] initWithDictionary:dic];
            [weakSelf.resultList addObject:model];
        }
        
        if (weakSelf.resultList.count == weakSelf.pageCount) {
            weakSelf.isLoadMore = YES;
        }else{
            weakSelf.isLoadMore = NO;
        }
        
        result(1,nil,nil);
    } error:^(NSString *errorMsg) {
        result(0,nil,errorMsg);
    }];

}

@end
